package com.xishu.foodpanda;

import com.xishu.config.ContextConstant;
import com.xishu.entity.foodpanda.Product;
import com.xishu.entity.shop.*;
import com.xishu.service.ItemService;
import com.xishu.to.foodpanda.*;
import com.xishu.util.Tools;
import org.apache.commons.chain.Command;
import org.apache.commons.chain.Context;
import org.apache.commons.chain.impl.ChainBase;
import org.apache.commons.chain.impl.ContextBase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

public class ProductChain extends ChainBase {
    private static Logger logger = LoggerFactory.getLogger(ProductChain.class);

    public ProductChain() {
    }

    public Map toMap(Product product, Long menuId) throws Exception {
        ProductChain productChain = new ProductChain();
        productChain.addCommand(new CommonProductToMap());
        Context context = new ContextBase();
        context.put(ContextConstant.PRODUCT, product);
        context.put(ContextConstant.MAP, new LinkedHashMap<>());
        context.put(ContextConstant.MENU_ID, menuId);
        productChain.execute(context);

        Map map = (Map) context.get(ContextConstant.MAP);
        return map;
    }

    public Map toToppingProductMap(Product product, Long menuId) throws Exception {
        ProductChain productChain = new ProductChain();
        productChain.addCommand(new DefineToppingProductCmd());
        Context context = new ContextBase();
        context.put(ContextConstant.PRODUCT, product);
        context.put(ContextConstant.MAP, new LinkedHashMap<>());
        context.put(ContextConstant.MENU_ID, menuId);
        productChain.execute(context);

        Map map = (Map) context.get(ContextConstant.MAP);
        return map;
    }

    public Map toSetMenuToppingProductMap(Product product, Long menuId) throws Exception {
        ProductChain productChain = new ProductChain();
        productChain.addCommand(new DefineSetMenuToppingProductCmd());
        Context context = new ContextBase();
        context.put(ContextConstant.PRODUCT, product);
        context.put(ContextConstant.MAP, new LinkedHashMap<>());
        context.put(ContextConstant.MENU_ID, menuId);
        productChain.execute(context);

        Map map = (Map) context.get(ContextConstant.MAP);
        return map;
    }

    public Map toSetMenuFixItemDetailProductMap(Product product) throws Exception {
        ProductChain productChain = new ProductChain();
        productChain.addCommand(new toSetMenuFixItemDetailProductMapCmd());
        Context context = new ContextBase();
        context.put(ContextConstant.PRODUCT, product);
        context.put(ContextConstant.MAP, new LinkedHashMap<>());
        productChain.execute(context);

        Map map = (Map) context.get(ContextConstant.MAP);
        return map;
    }

    public Map toToppingMap(Product product, Long menuId) throws Exception {
        ProductChain productChain = new ProductChain();
        productChain.addCommand(new DefineToppingAndUnderProduct());
        productChain.addCommand(new DefineSetMenuToppingAndUnderProductCmd());
        Context context = new ContextBase();
        context.put(ContextConstant.PRODUCT, product);
        context.put(ContextConstant.MAP, new LinkedHashMap<>());
        context.put(ContextConstant.MENU_ID, menuId);
        context.put(ContextConstant.TOP_INDEX, 1);
        productChain.execute(context);

        Map map = (Map) context.get(ContextConstant.MAP);
        return map;
    }

    public Map toVariantMap(Product product, Long menuId) throws Exception {
        ProductChain productChain = new ProductChain();
        productChain.addCommand(new DefineVariant());
        Context context = new ContextBase();
        context.put(ContextConstant.PRODUCT, product);
        context.put(ContextConstant.MAP, new LinkedHashMap<>());
        context.put(ContextConstant.MENU_ID, menuId);
        productChain.execute(context);

        Map map = (Map) context.get(ContextConstant.MAP);
        return map;
    }


}

class DefineToppingAndUnderProduct implements Command {
    private static Logger logger = LoggerFactory.getLogger(DefineToppingAndUnderProduct.class);
    private AtomicInteger atomicInteger = new AtomicInteger(0);

    @Override
    public boolean execute(Context context) throws Exception {
        Product product = (Product) context.get(ContextConstant.PRODUCT);
        Map map = (Map) context.get(ContextConstant.MAP);
        int toppingIndex = (Integer) context.get(ContextConstant.TOP_INDEX);

        if (!FoodPandaBaseService.isCommonProductHasDetail(product)) {
            logger.info("{} product do not has the detail", product.getId());
            return false;
        }

        List<ItemDetail> itemDetailList = product.getItemDetailList();
        for (ItemDetail itemDetail : itemDetailList) {
            //定义细节名称
            FoodPandaTopping itemDetailTopping = new FoodPandaTopping();
            itemDetailTopping.setTitle(new FoodPandaZhEn(itemDetail.getName_zh(), itemDetail.getName_en()));
            itemDetailTopping.setId(FoodPandaBaseService.generateToppingId(product.getId(), itemDetail.getId()));
            itemDetailTopping.setQuantity(new QuantitySelect(itemDetail.getMinSelect(), itemDetail.getMaxSelect()));
            itemDetailTopping.setOrder(toppingIndex++);

            //只添加id, type, price的 FoodPandaPrice
            List<FoodPandaProduct> nameAndPriceProductList = itemDetail.getNameAndPriceList().stream().map(nameAndPrice -> {
                FoodPandaProduct nameAndPriceProduct = new FoodPandaProduct();
                nameAndPriceProduct.setId(FoodPandaBaseService.generateToppingProductId(itemDetail.getId(), nameAndPrice.getId()));
                nameAndPriceProduct.setPrice(nameAndPrice.getPrice());
                nameAndPriceProduct.setOrder(atomicInteger.getAndAdd(1));
                return nameAndPriceProduct;
            }).collect(Collectors.toList());
            itemDetailTopping.setProducts(nameAndPriceProductList);
            Map<String, Object> stringObjectMap = FoodPandaBaseService.addIdMap(itemDetailTopping);
            map.putAll(stringObjectMap);
        }

        context.put(ContextConstant.TOP_INDEX, toppingIndex);
        return false;
    }
}

class DefineSetMenuToppingAndUnderProductCmd implements Command, Tools {
    private static Logger logger = LoggerFactory.getLogger(DefineSetMenuToppingAndUnderProductCmd.class);
    private AtomicInteger atomicInteger = new AtomicInteger(0);

    @Override
    public boolean execute(Context context) throws Exception {
        Product product = (Product) context.get(ContextConstant.PRODUCT);
        Map map = (Map) context.get(ContextConstant.MAP);
        int toppingIndex = (Integer)context.get(ContextConstant.TOP_INDEX);

        if (!getBoolean(product.getSetMenu())) {
            logger.info("{} product is not set menu", product.getId());
            return false;
        }

        List<SetMenuOneItem> setMenuOneItemList = product.getSetMenuOneItemList();
        for (SetMenuOneItem setMenuOneItem : setMenuOneItemList) {
            FoodPandaTopping foodPandaTopping = new FoodPandaTopping();

            foodPandaTopping.setOrder(toppingIndex++);

            //固定菜，采用菜本身的名称
            if (getBoolean(setMenuOneItem.getFixed())) {
                Item item = setMenuOneItem.getItemList().get(0);
                foodPandaTopping.setTitle(new FoodPandaZhEn(item.getName_zh(), item.getName_en()));
            } else {
                foodPandaTopping.setTitle(new FoodPandaZhEn(setMenuOneItem.getCatalog_zh(), setMenuOneItem.getCatalog_en()));
            }

            foodPandaTopping.setId(FoodPandaBaseService.generateToppingId(product.getId(), setMenuOneItem.getId()));

            //固定菜，根据实际的数量来决定最大值和最小值，并且最大值和最小值是相同的
            if (!getBoolean(setMenuOneItem.getFixed())) {
                foodPandaTopping.setQuantity(new QuantitySelect(setMenuOneItem.getMinNumber().longValue(), setMenuOneItem.getMaxNumber().longValue()));
            } else {
                //最大，最小都一样的
                foodPandaTopping.setQuantity(new QuantitySelect(setMenuOneItem.getItemNumber().longValue(), setMenuOneItem.getItemNumber().longValue()));
            }

            if (!getBoolean(setMenuOneItem.getFixed())) {
                //添加id,type, price的 FoodPandaPrice
                List<FoodPandaProduct> setMenuProductList = setMenuOneItem.getItemList().stream().map(item -> {
                    FoodPandaProduct setMenuUnderProduct = new FoodPandaProduct();
                    setMenuUnderProduct.setId(FoodPandaBaseService.generateSetMenuToppingProductId(setMenuOneItem.getId(), item.id));
                    setMenuUnderProduct.setPrice(item.getSetMenuAddPrice());
                    setMenuUnderProduct.setOrder(atomicInteger.getAndAdd(1));
                    return setMenuUnderProduct;
                }).collect(Collectors.toList());
                foodPandaTopping.setProducts(setMenuProductList);
            } else {
                Optional<Item> setMenuItem = FoodPandaBaseService.getSetMenuItem(setMenuOneItem);

                if (!setMenuItem.isPresent()) {
                    logger.info("set menu item not exist");
                    continue;
                }

                Optional<Item> itemOptional = FoodPandaBaseService.getSetMenuItem(setMenuOneItem);
                if (!itemOptional.isPresent()) {
                    logger.info("item not exit");
                    continue;
                }

                Item item = itemOptional.get();
                Double price = showMoneyDouble(FoodPandaBaseService.getFixItemPrice(setMenuOneItem));

                List<FoodPandaProduct> foodPandaProductList = new ArrayList<>();

                for (Integer i = 0; i < setMenuOneItem.getItemNumber(); i++) {
                    FoodPandaProduct setMenuUnderProduct = new FoodPandaProduct();
                    setMenuUnderProduct.setId(FoodPandaBaseService.generateSetMenuToppingProductId(setMenuOneItem.getId(), item.id, i));
                    setMenuUnderProduct.setPrice(price);
                    setMenuUnderProduct.setOrder(atomicInteger.getAndAdd(1));
                    foodPandaProductList.add(setMenuUnderProduct);
                }

                foodPandaTopping.setProducts(foodPandaProductList);
            }

            Map<String, Object> stringObjectMap = FoodPandaBaseService.addIdMap(foodPandaTopping);
            map.putAll(stringObjectMap);

            //当前还在setMenuOneItem下面
            //如果套餐下面的固定菜还有细节，那么分别添加对应的细节，有几个菜生成几个
            if (!getBoolean(setMenuOneItem.getFixed())) {
                continue;
            }

            Optional<Item> itemOptional = FoodPandaBaseService.getSetMenuItem(setMenuOneItem);
            if (!itemOptional.isPresent()) {
                continue;
            }

            Item item = itemOptional.get();
            if (!ItemService.isCommonItemHasDetail(item)) {
                continue;
            }

            for (Integer index = 1; index <= setMenuOneItem.getItemNumber(); index++) {
                final Integer thisIndex = index;

                for (ItemDetail itemDetail : item.getItemDetailList()) {
                    FoodPandaTopping setMenuFixItemTopping = new FoodPandaTopping();
                    setMenuFixItemTopping.setOrder(toppingIndex++);

                    if (setMenuOneItem.getItemNumber() == 1) {
                        //只有一个，不显示个数
                        setMenuFixItemTopping.setTitle(new FoodPandaZhEn(String.format("%s - %s", item.getName_zh(), itemDetail.getName_zh()),
                                String.format("%s - %s", item.getName_en(), itemDetail.getName_en())));
                    } else {
                        //多于1个，显示个数
                        setMenuFixItemTopping.setTitle(new FoodPandaZhEn(String.format("%s %s - %s", item.getName_zh(), index, itemDetail.getName_zh()),
                                String.format("%s %s - %s", item.getName_en(), index, itemDetail.getName_en())));
                    }

                    setMenuFixItemTopping.setId(FoodPandaBaseService.generateFixItemDetailToppingId(product.getId(), item.getId(), itemDetail.getId(), index));
                    setMenuFixItemTopping.setQuantity(new QuantitySelect(itemDetail.getMinSelect(), itemDetail.getMaxSelect()));

                    //添加产品
                    List<FoodPandaProduct> pandaProductList = itemDetail.getNameAndPriceList().stream().map(nameAndPrice -> {
                        FoodPandaProduct foodPandaProduct = new FoodPandaProduct();
                        foodPandaProduct.setId(FoodPandaBaseService.generateFixSetMenuItemDetailProductId(setMenuOneItem.getId(), item.id, itemDetail.getId(), nameAndPrice.getId(), thisIndex));
                        foodPandaProduct.setPrice(nameAndPrice.getPrice());
                        foodPandaProduct.setOrder(atomicInteger.getAndAdd(1));
                        return foodPandaProduct;
                    }).collect(Collectors.toList());

                    setMenuFixItemTopping.setProducts(pandaProductList);
                    map.putAll(FoodPandaBaseService.addIdMap(setMenuFixItemTopping));
                }
            }
        }

        context.put(ContextConstant.TOP_INDEX, toppingIndex);
        return false;
    }
}

class DefineToppingProductCmd implements Command, Tools {
    private static Logger logger = LoggerFactory.getLogger(DefineToppingProductCmd.class);

    @Override
    public boolean execute(Context context) throws Exception {
        Product product = (Product) context.get(ContextConstant.PRODUCT);
        Map map = (Map) context.get(ContextConstant.MAP);

        if (!FoodPandaBaseService.isCommonProductHasDetail(product)) {
            logger.info("{} product do not has the detail", product.getId());
            return false;
        }

        List<ItemDetail> itemDetailList = product.getItemDetailList();
        for (ItemDetail itemDetail : itemDetailList) {
            //定义细节下面的每一个选择
            for (NameAndPrice nameAndPrice : itemDetail.getNameAndPriceList()) {
                FoodPandaProduct nameAndPriceProduct = new FoodPandaProduct();
                nameAndPriceProduct.setTitle(new FoodPandaZhEn(nameAndPrice.getName_zh(), nameAndPrice.getName_en()));

                nameAndPriceProduct.setId(FoodPandaBaseService.generateToppingProductId(itemDetail.getId(), nameAndPrice.getId()));
                nameAndPriceProduct.setPrice(nameAndPrice.getPrice());
                map.putAll(FoodPandaBaseService.addIdMap(nameAndPriceProduct));
            }
        }

        return false;
    }
}

class toSetMenuFixItemDetailProductMapCmd implements Command, Tools {
    private static Logger logger = LoggerFactory.getLogger(DefineSetMenuToppingProductCmd.class);

    @Override
    public boolean execute(Context context) throws Exception {
        Product product = (Product) context.get(ContextConstant.PRODUCT);
        Map map = (Map) context.get(ContextConstant.MAP);
        if (!getBoolean(product.getSetMenu())) {
            logger.info("not the set menu product {}", product.getId());
            return false;
        }

        List<SetMenuOneItem> setMenuOneItemList = getList(product.getSetMenuOneItemList());
        List<SetMenuOneItem> fixStMenuOneItemList = setMenuOneItemList.stream().filter(setMenuOneItem -> getBoolean(setMenuOneItem.getFixed())).collect(Collectors.toList());

        for (SetMenuOneItem setMenuOneItem : fixStMenuOneItemList) {
            Item item = FoodPandaBaseService.getSetMenuItem(setMenuOneItem).get();
            if (!ItemService.isCommonItemHasDetail(item)) {
                logger.info("item {} not has detail", item.getId());
                continue;
            }

            for (Integer index = 1; index <= setMenuOneItem.getItemNumber(); index++) {
                for (ItemDetail itemDetail : getList(item.getItemDetailList())) {
                    for (NameAndPrice nameAndPrice : itemDetail.getNameAndPriceList()) {
                        FoodPandaProduct foodPandaProduct = new FoodPandaProduct();
                        foodPandaProduct.setTitle(new FoodPandaZhEn(nameAndPrice.getName_zh(), nameAndPrice.getName_en()));
                        foodPandaProduct.setId(FoodPandaBaseService.generateFixSetMenuItemDetailProductId(setMenuOneItem.getId(), item.getId(), itemDetail.getId(), nameAndPrice.getId(), index));
                        foodPandaProduct.setPrice(nameAndPrice.getPrice());
                        map.putAll(FoodPandaBaseService.addIdMap(foodPandaProduct));
                    }
                }
            }
        }

        return false;
    }
}

class DefineSetMenuToppingProductCmd implements Command, Tools {
    private static Logger logger = LoggerFactory.getLogger(DefineSetMenuToppingProductCmd.class);

    @Override
    public boolean execute(Context context) throws Exception {
        Product product = (Product) context.get(ContextConstant.PRODUCT);
        Map map = (Map) context.get(ContextConstant.MAP);
        if (!getBoolean(product.getSetMenu())) {
            logger.info("not the set menu product {}", product.getId());
            return false;
        }

        //定义套餐里面的每一道菜
        List<SetMenuOneItem> setMenuOneItemList = getList(product.getSetMenuOneItemList());
        for (SetMenuOneItem setMenuOneItem : setMenuOneItemList) {
            //如果是固定菜，每个菜分别添加一个Product
            if (getBoolean(setMenuOneItem.getFixed())) {
                Item item = setMenuOneItem.getItemList().get(0);
                Double price = showMoneyDouble(FoodPandaBaseService.getFixItemPrice(setMenuOneItem));

                //有多少份数就构建几个
                for (Integer i = 0; i < setMenuOneItem.getItemNumber(); i++) {
                    FoodPandaProduct foodPandaProduct = new FoodPandaProduct();
                    foodPandaProduct.setTitle(new FoodPandaZhEn(item.getName_zh(), item.getName_en()));
                    foodPandaProduct.setId(FoodPandaBaseService.generateSetMenuToppingProductId(setMenuOneItem.getId(), item.getId(), i));
                    foodPandaProduct.setPrice(price);
                    map.putAll(FoodPandaBaseService.addIdMap(foodPandaProduct));
                }

                continue;
            }

            for (Item item : setMenuOneItem.getItemList()) {
                FoodPandaProduct foodPandaProduct = new FoodPandaProduct();
                foodPandaProduct.setTitle(new FoodPandaZhEn(item.getName_zh(), item.getName_en()));
                foodPandaProduct.setId(FoodPandaBaseService.generateSetMenuToppingProductId(setMenuOneItem.getId(), item.getId()));
                foodPandaProduct.setPrice(item.getSetMenuAddPrice());
                map.putAll(FoodPandaBaseService.addIdMap(foodPandaProduct));
            }
        }

        return false;
    }
}

class CommonProductToMap implements Command, Tools {
    private static Logger logger = LoggerFactory.getLogger(CommonProductToMap.class);

    @Override
    public boolean execute(Context context) throws Exception {
        Long menuId = (Long) context.get(ContextConstant.MENU_ID);
        Product product = (Product) context.get(ContextConstant.PRODUCT);
        Map map = (Map) context.get(ContextConstant.MAP);

        HashMap<String, Object> productMap = new HashMap<>();

        //将界面上的Product转化成传输类型FoodPandaProduct
        FoodPandaProduct foodPandaProduct = new FoodPandaProduct();
        foodPandaProduct.setActive(true);
        foodPandaProduct.setId(FoodPandaBaseService.generateProductId(menuId, product.getCategoryId(), product.getId()));
        foodPandaProduct.setTitle(new FoodPandaZhEn(product.getName_zh(), product.getName_en()));

        //添加描述
        if (isNotEmpty(product.getDescription_zh()) || isNotEmpty(product.getDescription_en())) {
            foodPandaProduct.setDescription(new FoodPandaZhEn(product.getDescription_zh(), product.getDescription_en()));
        }

        //设置价格
        List<PriceConfig> priceConfigList = product.getPriceConfigList();
        if (isEmpty(priceConfigList)) {
            logger.info("product {} price config list is empty", product.getId());
            return false;
        }
        Optional<PriceConfig> priceConfigOptional = priceConfigList.stream().filter(p -> equals(p.getSceneId(), menuId)).findAny();

        if (!priceConfigOptional.isPresent()) {
            logger.info("can not find the menu id {} in product {}, price config list is {}", menuId, product.getId(), priceConfigList);
            return false;
        }

        foodPandaProduct.setOrder(product.getShowOrder());
        foodPandaProduct.setPrice(priceConfigOptional.get().getPrice());
        if (isNotEmpty(product.getImgId())) {
            foodPandaProduct.setImages(new FoodPandaBase(product.getImgId(), FoodPandaBaseService.IMAGE));
        }

        //如果是普通菜并且有细节，对么添加细节
        if (FoodPandaBaseService.isCommonProductHasDetail(product) || getBoolean(product.getSetMenu())) {
            FoodPandaBase foodPandaBase = new FoodPandaBase();
            foodPandaBase.setId(FoodPandaBaseService.generateVariantId(menuId, product.getId()));
            foodPandaBase.setType(FoodPandaBaseService.PRODUCT);

            foodPandaProduct.setVariants(Arrays.asList(foodPandaBase));
        }

        productMap.putAll(FoodPandaBaseService.beanToMap(foodPandaProduct));
        map.put(foodPandaProduct.getId(), productMap);

        return false;
    }
}

class DefineVariant implements Command, Tools {
    private static Logger logger = LoggerFactory.getLogger(DefineVariant.class);
    private int toppingOrder = 1;

    @Override
    public boolean execute(Context context) throws Exception {
        logger.info("define variant");
        Long menuId = (Long) context.get(ContextConstant.MENU_ID);
        Product product = (Product) context.get(ContextConstant.PRODUCT);
        Map map = (Map) context.get(ContextConstant.MAP);


        //添加variant的定义
        if (getBoolean(product.getSetMenu()) || FoodPandaBaseService.isCommonProductHasDetail(product)) {
            FoodPandaVariant foodPandaVariant = new FoodPandaVariant();
            foodPandaVariant.setTitle(new FoodPandaZhEn(product.getName_zh(), product.getName_en()));
            foodPandaVariant.setId(FoodPandaBaseService.generateVariantId(menuId, product.getId()));
            foodPandaVariant.setParent(new FoodPandaBase(FoodPandaBaseService.generateProductId(menuId, product.getCategoryId(), product.getId()), FoodPandaBaseService.PRODUCT));

            //找到对应场景的价格
            Optional<PriceConfig> priceConfigOptional = product.getPriceConfigList().stream().filter(priceConfig -> equals(priceConfig.getSceneId(), menuId)).findAny();

            if (!priceConfigOptional.isPresent()) {
                logger.info("can not find the price , product {}", product.getId());
                return false;
            }

            PriceConfig priceConfig = priceConfigOptional.get();
            foodPandaVariant.setPrice(priceConfig.getPrice());

            if (FoodPandaBaseService.isCommonProductHasDetail(product)) {
                List<FoodPandaBase> toppingList = product.getItemDetailList().stream().map(itemDetail -> {
                    FoodPandaOrder foodPandaBase = new FoodPandaOrder();
                    foodPandaBase.setId(FoodPandaBaseService.generateToppingId(product.getId(), itemDetail.getId()));
                    foodPandaBase.setType(FoodPandaBaseService.TOPPING);
                    foodPandaBase.setOrder(toppingOrder++);
                    return foodPandaBase;
                }).collect(Collectors.toList());

                foodPandaVariant.setToppings(toppingList);
            } else {
                List<FoodPandaBase> toppingList = product.getSetMenuOneItemList().stream().map(setMenuOneItem -> {
                    FoodPandaOrder foodPandaBase = new FoodPandaOrder();
                    foodPandaBase.setId(FoodPandaBaseService.generateToppingId(product.getId(), setMenuOneItem.getId()));
                    foodPandaBase.setType(FoodPandaBaseService.TOPPING);
                    foodPandaBase.setOrder(toppingOrder++);
                    return foodPandaBase;
                }).collect(Collectors.toList());

                //如果还有固定菜，并且固定菜下面还有固定菜细节的TOPPING
                List<SetMenuOneItem> fixSetMenuOneItemList = product.getSetMenuOneItemList().stream().filter(setMenuOneItem -> getBoolean(setMenuOneItem.getFixed())).collect(Collectors.toList());
                for (SetMenuOneItem setMenuOneItem : fixSetMenuOneItemList) {
                    Item item = FoodPandaBaseService.getSetMenuItem(setMenuOneItem).get();

                    if (!ItemService.isCommonItemHasDetail(item)) {
                        logger.info("fix item {} but not has details", item.getId());
                        continue;
                    }

                    for (Integer index = 1; index <= setMenuOneItem.getItemNumber(); index++) {
                        for (ItemDetail itemDetail : item.getItemDetailList()) {
                            FoodPandaOrder foodPandaBase = new FoodPandaOrder();
                            foodPandaBase.setId(FoodPandaBaseService.generateFixItemDetailToppingId(product.getId(), item.getId(), itemDetail.getId(), index));
                            foodPandaBase.setType(FoodPandaBaseService.TOPPING);
                            foodPandaBase.setOrder(toppingOrder++);
                            toppingList.add(foodPandaBase);
                        }
                    }
                }

                foodPandaVariant.setToppings(toppingList);
            }

            map.put(foodPandaVariant.getId(), FoodPandaBaseService.beanToMap(foodPandaVariant));
        }

        return false;
    }
}
